package src.com.bjsxt.memento.jike;

import lombok.Data;

import java.util.ArrayList;

public class Originator2 {

    private ArrayList<String> state;

    public Originator2() {
        state = new ArrayList<>();
    }

    /**
     * 创建备份
     * @return MementoIF
     */
    public MementoIF createMemento() {
        return new Memento(state);
    }

    /**
     * 恢复备份
     * @param memento MementoIF
     */
    public void restoreMemento(MementoIF memento) {
        state = ((Memento) memento).getState();
    }

    public void testState1() {
        state = new ArrayList<>();
        state.add("blood:320");
        state.add("progress:gate2 mid");
        state.add("enemy:15");

    }

    public void testState2() {
        state = new ArrayList<>();
        state.add("blood:230");
        state.add("progress:gate8 last");
        state.add("enemy:12");

    }

    public void showState() {
        System.out.println("now state:" + state.toString());
    }

    @Data
    private class Memento implements MementoIF {

        private ArrayList<String> state;

        private Memento(ArrayList<String> state) {
            this.state = new ArrayList(state);
        }

    }

}
